package com.zhanglijie.base.threadgroup;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/3/30 0030 1:37
 */
public class ThreadGroup1 {
    public static void main(String[] args) {

        java.lang.ThreadGroup threadGroup = new java.lang.ThreadGroup("threadGroup1");
        System.out.println(threadGroup.getParent());//在main函数中创建的线程组就是main线程组
        System.out.println(threadGroup.getParent()
            .getParent());//其曾祖父线程组为system
        System.out.println("main 函数的线程组" + Thread.currentThread()
            .getThreadGroup());//main函数的线程组是main线程组

        System.out.println("===============================");
        Thread t1 = new Thread(threadGroup, () -> {

        }, "thread1");
        t1.start();
        Thread t2 = new Thread(threadGroup, () -> {

        }, "thread2");
        t2.start();

        Thread t3 = new Thread(threadGroup, () -> {

        }, "thread3");
        System.out.println("t1的线程组是" + t1.getThreadGroup());//就是指定的threadGroup1
        System.out.println("t1的祖父线程组是" + t1.getThreadGroup()
            .getParent());//就是该线程组的父线程组

        System.out.println("++++++++++++++线程组活跃线程和孩子线程组个数+++++++++++++");
        System.out.println(threadGroup.activeCount());
        System.out.println(threadGroup.activeGroupCount());
        new java.lang.ThreadGroup(threadGroup, "threadgroup1的孩子线程组");
        System.out.println(threadGroup.activeCount());
        System.out.println(threadGroup.activeGroupCount());
    }
}
